import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
// @ts-expect-error haha
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [
                ElementPlusResolver({importStyle: "sass"})
            ],
        }),
    ],
    resolve: {
        alias: {
            "@": path.resolve("./src")
        }
    },
    server: {
        proxy: {
            '/api': {
                target: "https://sph-api.atguigu.cn/",
                // 控制转发时的端口
                changeOrigin: true,
                // 重写路径，在转发时将 api 换成 ''
                rewrite: (path) => path.replace(/^\/api/, ''),
                // 是否支持 websocket
                ws: true
            }
        },
        port: 3000,
    },
    css: {
        preprocessorOptions: {
            scss: {
                // 自动导入定制化样式文件进行样式覆盖
                additionalData: `
          @use "@/styles/index.scss" as *;
          @use "@/styles/var.scss" as *;
            `
            }
        }
    }
})
